import 'package:flutter/cupertino.dart';
import 'package:provider/provider.dart';

import '../../../../lib_baseview/lib_baseview.dart';
import '../../../../lib_baseview/theme/jr.dart';
import '../../../../lib_im/index.dart';
import 'gift_page_model.dart';

class GiftItemWidget extends StatelessWidget {
  final ImGitfModel gift;
  final VoidCallback onTap;

  const GiftItemWidget({required this.gift, required this.onTap});

  @override
  Widget build(BuildContext context) {
    final vm = context.watch<GiftPageModel>();
    final isSelected = vm.isGiftSelected(gift);

    return GestureDetector(
      onTap: onTap,
      child: Stack(
        alignment: Alignment.center,
        children: [
          // 内容主体（保持原有尺寸）
          Container(
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(10),
            ),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Expanded(child: image(gift.objectUrl ?? '')),
                Padding(
                  padding: const EdgeInsets.only(bottom: 2),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      JR.img('room/room_gift_price_icon.png',
                          width: 14, height: 14),
                      Text(
                        '${gift.price ?? 999}',
                        style: const TextStyle(
                          color: Color(0xFFffffff),
                          fontWeight: FontWeight.w500,
                          fontSize: 14,
                        ),
                      )
                    ],
                  ),
                ),
              ],
            ),
          ),

          // 选中边框（作为覆盖层）
          if (isSelected)
            Positioned.fill(
              child: Container(
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(10),
                  border: Border.all(
                    color: const Color(0xFFCEC3FF),
                    width: 1,
                  ),
                ),
              ),
            ),
        ],
      ),
    );
  }
}
